class iGamePlayerController extends SimplePC;

/** If True then we are in attract mode */
var bool bIsInAttractMode;

var MobileMenuPause PauseMenu;	// The Pause menu
	
simulated event PostBeginPlay()
{
	super.PostBeginPlay();
}

//exec function StartFire( optional byte FireModeNum );

function PlayerTick(float DeltaTime)
{
	Super.PlayerTick(DeltaTime);

	if (WorldInfo.IsConsoleBuild())
	{
		if (Abs(PlayerInput.aTurn) > 0.1 || Abs(PlayerInput.aLookUp) > 0.1)
			StartFire();
		else
			StopFire();
	}
}

state PlayerWalking
{
	ignores SeePlayer, HearNoise, Bump;

	function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
	{
		if( Pawn == None ) return;

		if (Role == ROLE_Authority)
		{
			// Update ViewPitch for remote clients
			Pawn.SetRemoteViewPitch( Rotation.Pitch );
		}

		Pawn.Acceleration = NewAccel;
	}

	function PlayerMove( float DeltaTime )
	{
		local vector			X,Y, NewAccel;
		local rotator			OldRotation;

		if( Pawn == None )
		{
			GotoState('Dead');
		}
		else
		{
			X = vect(1, 0, 0);
			Y = vect(0, 1, 0);

			// Update acceleration.
			NewAccel = PlayerInput.aForward*X + PlayerInput.aStrafe*Y;
			NewAccel.Z	= 0;
			NewAccel = Pawn.AccelRate * Normal(NewAccel);

			if (IsLocalPlayerController())
			{
				AdjustPlayerWalkingMoveAccel(NewAccel);
			}

			OldRotation = Rotation;			
			UpdateRotation( DeltaTime );

			if( Role < ROLE_Authority ) // then save this move and replicate it
			{
				ReplicateMove(DeltaTime, NewAccel, DCLICK_None, OldRotation - Rotation);
			}
			else
			{
				ProcessMove(DeltaTime, NewAccel, DCLICK_None, OldRotation - Rotation);
			}
		}
	}

	function UpdateRotation( float DeltaTime )
	{
		local Rotator   newRotation, ViewRotation;

		local vector X,Y;
		local vector facingDirection, faceDir, PlaneHitPos;
		local float     hitLength;
	
		ViewRotation = Rotation;

		if (Pawn!=none)
		{
			Pawn.SetDesiredRotation(ViewRotation);

			if (!WorldInfo.IsConsoleBuild())
			{
				facingDirection = Pawn.GetPawnViewLocation();
				hitLength = -((vect(0,0,1) dot (iGameHUD(myHud).MouseLocation - facingDirection)) / (vect(0,0,1) dot iGameHUD(myHud).MouseDirection));
				PlaneHitPos = (iGameHUD(myHud).MouseLocation + iGameHUD(myHud).MouseDirection * hitLength);
		
				NewRotation = pawn.GetBaseAimRotation();
				NewRotation.Yaw = rotator(PlaneHitPos - facingDirection).Yaw; // only update yaw
			}
			else
			{
				X = vect(1, 0, 0);
				Y = vect(0, 1, 0);

				facingDirection = Normal(PlayerInput.aTurn*Y + PlayerInput.aLookUp*X);

				// Setup player to face facingDirection, or if that is zero, then the movementDirection
				faceDir = facingDirection;
				if (faceDir == vect(0,0,0))
					faceDir = Normal(Pawn.Velocity);
		
				// Make the character rotate towards the target rotation
				if (faceDir == vect(0,0,0))
				{
					//rigidbody.angularVelocity = Vector3.zero;
					SetRotation(ViewRotation);
				}
				else 
				{			
					ViewRotation.Yaw = RInterpTo (Rotation, rotator(faceDir), DeltaTime, 10, false).Yaw;
					SetRotation(ViewRotation);
				}
	
				NewRotation = ViewRotation;
				NewRotation.Roll = Rotation.Roll;
			}

			Pawn.FaceRotation(NewRotation, deltatime);
		}
		else
		{
			super.UpdateRotation(DeltaTime);
		}
	}   
}

defaultproperties
{
	InputClass = class'iGamePlayerInput'
}